package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;


    @GetMapping
    public Result studentSelect(StudentQueryParam studentQueryParam){
        log.info("分页查询学员信息");
        PageResult<Student> pageResult = studentService.studentSelect(studentQueryParam);
        return Result.success(pageResult);
    }

    @DeleteMapping("/{ids}")
    public Result studentDelete(@PathVariable List<Integer> ids){
        log.info("删除学员");
        studentService.studentDelete(ids);
        return Result.success();
    }

    @PostMapping
    public Result studentInsert(@RequestBody Student student){
        log.info("添加学员");
        studentService.studentInsert(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result studentGetById(@PathVariable Integer id){
        log.info("根据id查询");
        Student student = studentService.studentGetById(id);
        return Result.success(student);
    }

    @PutMapping
    public Result studentUpdate(@RequestBody Student student){
        log.info("修改学员信息");
        studentService.studentUpdate(student);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result studentDisciplinary(@PathVariable Integer id,@PathVariable Integer score){
        log.info("违纪处理");
        studentService.studentDisciplinary(id,score);
        return Result.success();
    }
}
